import { Component } from '@angular/core';
import {Subscription} from "rxjs";
import {UserService} from "../../service/user.service";

@Component({
  selector: 'app-manager-user',
  templateUrl: './manager-user.component.html',
    styleUrls: ["../../../assets/css/manager/bootstrap.css",
        "../../../assets/css/manager/font-awesome.css",
        "../../../assets/css/manager/morris-0.4.3.min.css",
        "../../../assets/css/manager/custom-styles.css",
        "../../../assets/css/manager/google.css",
        "manager-user.component.css"
    ]
})
export class ManagerUserComponent {
    countries: string[] = ['','CN','USA'];
    deleteUsers: string[] = [];
    selectCountry: string = '';
    inputUserName: string = '';
    usersVO: any;
    editing: string = "";

    constructor(private userService: UserService) {
    }

    searchUser() {
        console.log(this.selectCountry);
        this.userService.getUsers(this.inputUserName, this.selectCountry).subscribe(users => {
            this.usersVO = users?.data;
        });
    }

    isEditable() {
        return !this.editing;
    }

    isDeletable() {
        return true;
    }

    saveRow(id: string) {
        this.editing = "";
        let row = document.getElementById(id);
        // @ts-ignore
        row.classList.remove("edit");
    }

    cancelRow(id: string) {
        this.editing = "";
        let row = document.getElementById(id);
        // @ts-ignore
        row.classList.remove("edit");
    }

    editRow(id: string) {
        this.editing = id+"";
        let row = document.getElementById(id);
        // @ts-ignore
        row.classList.add("edit");
    }

    dropRow(id: string) {
        this.deleteUsers.push(id);
    }
}
